﻿using System;
using System.Collections.Generic;
using Scrum.Net.Interfaces;
using Scrum.Net.Utilities;

namespace Scrum.Net.Classes
{
    public class Sprint : ObservableObject, ISprint
    {
        private string _name;
        private DateTime _startDate;
        private DateTime _endDate;

        private readonly IProject _project;

        private readonly IList<ISprintStory> _backlog;
        private readonly IList<ISprintGoal> _goals;
        private readonly IList<ISprintAvailability> _availability;

        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                RaisePropertyChanged("Name");
            }
        }

        public DateTime StartDate
        {
            get { return _startDate; }
            set
            {
                _startDate = value;
                RaisePropertyChanged("StartDate");
            }
        }

        public DateTime EndDate
        {
            get { return _endDate; }
            set
            {
                _endDate = value;
                RaisePropertyChanged("EndDate");
            }
        }


        public IList<ISprintStory> Backlog
        {
            get { return _backlog; }
        }

        public IList<ISprintGoal> Goals
        {
            get { return _goals; }
        }

        public IList<ISprintAvailability> Availability
        {
            get { return _availability; }
        }

        public void StartSprint()
        {
            foreach (IUser t in _project.Users)
            {
                _availability.Add(new SprintAvailability(this, t));
            }
        }

        public void CalculatingAvailabilities()
        {
            foreach (ISprintAvailability sprintAvailability in Availability)
            {
                sprintAvailability.CalculatingAvailabilty();
            }
        }

        public Sprint(IProject project, string name)
        {
            Name = name;
            _project = project;

            _backlog = new List<ISprintStory>();
            _goals = new List<ISprintGoal>();
            _availability = new List<ISprintAvailability>();
        }
    }
}
